package com.zyw.util;

import com.zyw.entity.ProcurementMaterialAnalysis;
import com.zyw.entity.ProcurementOrders;

import java.util.List;

public class ProcurementOrdersUtil {


    public static ProcurementOrders conversion(String id, List<ProcurementMaterialAnalysis>dataList1,List<ProcurementMaterialAnalysis>dataList2){
        Double total=0.0;
        ProcurementOrders procurementOrders = new ProcurementOrders();
        procurementOrders.setId(id);
        String lining="";
        String liningNum = "";
        String liningSubtotal ="";
        if (dataList1.size()!=0){
            for (ProcurementMaterialAnalysis data : dataList1) {
                lining +=data.getLiningName()+"/";
                liningNum+=data.getLiningNum()+"/";
                liningSubtotal += data.getLiningSubtotal()+"/";
                total += Double.valueOf(data.getLiningSubtotal());
            }
            lining = lining.substring(0,lining.lastIndexOf("/"));
            liningNum = liningNum.substring(0,liningNum.lastIndexOf("/"));
            liningSubtotal = liningSubtotal.substring(0,liningSubtotal.lastIndexOf("/"));
        }

        procurementOrders.setLining(lining);
        procurementOrders.setLiningNum(liningNum);
        procurementOrders.setLiningSubtotal(liningSubtotal);

        String ingredients ="";
        String ingredientsNum ="";
        String ingredientsSubtotal ="";
        if (dataList2.size()!=0) {
            for (ProcurementMaterialAnalysis data : dataList2) {
                ingredients += data.getLiningName() + "/";
                ingredientsNum += data.getLiningNum() + "/";
                ingredientsSubtotal += data.getLiningSubtotal() + "/";
                total += Double.valueOf(data.getLiningSubtotal());
            }
            ingredients = ingredients.substring(0, ingredients.lastIndexOf("/"));
            ingredientsNum = ingredientsNum.substring(0, ingredientsNum.lastIndexOf("/"));
            ingredientsSubtotal = ingredientsSubtotal.substring(0, ingredientsSubtotal.lastIndexOf("/"));
        }
        procurementOrders.setIngredients(ingredients);
        procurementOrders.setIngredientsNum(ingredientsNum);
        procurementOrders.setIngredientsSubtotal(ingredientsSubtotal);

        procurementOrders.setTotal(String.valueOf(total));
        return procurementOrders;
    }
}
